package com.syg.servlet04;

import com.syg.toolkit.Constants;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/listSrevlet")
public class _03_Disable_Cookie_ListCartServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");//设置响应编码格式
        PrintWriter out = resp.getWriter();//获取响应字符流
        HttpSession session = req.getSession();//创建session(获取session)
        List<_03_Disable_Cookie.Book> list = (List) session.getAttribute("list");
        if(null == list|| 0==list.size()){
            out.write("对不起，您还没有购买任何商品!!");
            return;
        }
        //显示用户买过的商品
        out.write("您买过如下商品:<br>");
        for(_03_Disable_Cookie.Book book : list){
            out.write(book.getName() + "<br/>");
        }
    }
}
